package com.csd.controller;

import com.csd.common.JsonBean;
import com.csd.pojo.SysCar;
import com.csd.service.CarListSerivce;
import com.csd.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 选车排序
 * 按租金排
 * 按热度排
 * @ PACKAGE:com.csd.controller
 * @ Author:LiWenJin
 * @ Date:2020/12/23  20:59
 */
@Controller
public class CarListController {
    @Autowired(required = false)
    private CarListSerivce carListSerivce;


    @RequestMapping("/carPList")
    @ResponseBody
    public JsonBean selectByPrice(Integer getid) {
        JsonBean bean = null;

        try {
            List<SysCar> list = carListSerivce.findPriceList(getid);
            bean = JsonUtils.createJsonBean(1, list);

        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0, e.getMessage());
        }

        return bean;

    }

    @RequestMapping("/carNList")
    @ResponseBody
    public JsonBean selectByNumber(Integer getid) {
        JsonBean bean = null;
        System.out.println(getid);
        try {
            List<SysCar> list = carListSerivce.findNumberList(getid);
            bean = JsonUtils.createJsonBean(1, list);

        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0, e.getMessage());
        }
        return bean;
    }


    @RequestMapping("/findCar")
    @ResponseBody
    public JsonBean findCar(Integer cid) {
        JsonBean bean = null;
        try {
            SysCar sysCar = carListSerivce.findCarById(cid);
            bean = JsonUtils.createJsonBean(1, sysCar);
        }catch (Exception e){
            bean = JsonUtils.createJsonBean(0, e.getMessage());
        }
        return bean;
    }


}
